
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class UserList extends JFrame{
    public UserList(String userid){

        SQLOperation sql=new SQLOperation();

        setTitle("Family List");
        Container container=getContentPane();
        setLayout(new BorderLayout());

        JPanel titlePanel=new JPanel();

        JLabel title=new JLabel("User Information");
        title.setFont(new Font("",Font.BOLD,20));

        titlePanel.add(title);

        String[] userAttributes={"uUID","phoneNum","gender","dateOfBirth"};
        String[] accountAttributes={"aName"};
        String[] attributes={"aName","uUID","phoneNum","gender","dateOfBirth"};


        Object[][] userDB=sql.search("User",userAttributes,"shanchu",1);

        Object[][] userInfo=new Object[userDB.length][5];
        for(int i=0;i< userDB.length;i++){
            userInfo[i][0]=sql.search("Account",accountAttributes,"UID",userDB[i][0])[0][0];
            for(int j=1;j<5;j++) userInfo[i][j]=userDB[i][j-1];
        }

        JTable userList=new JTable(userInfo,attributes);

        userList.setRowHeight(30);
        userList.setFont(new Font("",Font.PLAIN,15));

        userList.setEnabled(true);
        userList.getTableHeader().setFont(new Font("",Font.BOLD,20));
        JScrollPane scrollPane=new JScrollPane(userList);

        add(scrollPane,BorderLayout.CENTER);

        JButton back=new JButton("Back");
        back.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
            }
        });

        JButton addOne=new JButton("Add one");
        addOne.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // ADD
                setVisible(false);
                new UserAdd(userid);


            }
        });




        JPanel buttons=new JPanel();
        buttons.add(back);
        buttons.add(addOne);

        add(buttons,BorderLayout.SOUTH);






        setSize(600,500);
        setResizable(false);
        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        setVisible(true);



    }
}
